Populating ListView with type enumeration values

Hi All,

I have a function which works well populating a list view DBE with Attribute values, however I am struggling to amend this to list the enumerated values of a specified data type. The error is typically "array bounds exceeded."

Am I missing something obvious as I believe the loop is cycling through the attribute type values.

Many thanks for any steering

Mark
 

void getPlfm(Module m)
    {
                int numEle = noElems (currentPlfm)
                AttrType at = find(current Module,"platform")
                if(!null at && at.type == attrEnumeration)
                {
                        string szStrings[at.size]
                        int i = 0
                        for (i = 0; i < at.size; i++) 
                        szStrings[i] = at.strings[i]
                        
                        insert (currentPlfm,numEle,(szStrings[i]))
                numEle++
                }
        else
        {
                errorBox ("Attribute >"plat_attr"<is not an enumeration!")
        }    
        insertColumn(currentPlfm,0,"Platform List",200,iconNone)
    }

mwilliamson - Tue Sep 15 07:23:21 EDT 2009

Re: Populating ListView with type enumeration values
mwilliamson - Tue Sep 15 07:54:23 EDT 2009

Solved it with the use of Pekka's earlier type posting.

Re: Populating ListView with type enumeration values
dpechacek - Tue Sep 15 07:54:26 EDT 2009

Given that the array you create has a local scope inside the if statement, why are you even using the array? Or is this just example code? When I do this I just do:
 

for(i = 0; i < at.size; i++) {
   insert(list_DBE, i, at.strings[i]);
}

 


Part of your problem is due to the fact that you don't have {} around your for loop. This leads to the problem of your insert statement only executing once with i being equal to at.size which is beyond the values of your array after the for loop is done executing.

AAI Services, Textron
dpechacek@aai.textron.com
David.Pechacek@gmail.com

 

Re: Populating ListView with type enumeration values
mwilliamson - Tue Sep 15 08:51:31 EDT 2009

dpechacek - Tue Sep 15 07:54:26 EDT 2009

Given that the array you create has a local scope inside the if statement, why are you even using the array? Or is this just example code? When I do this I just do:
 

for(i = 0; i < at.size; i++) {
   insert(list_DBE, i, at.strings[i]);
}

 


Part of your problem is due to the fact that you don't have {} around your for loop. This leads to the problem of your insert statement only executing once with i being equal to at.size which is beyond the values of your array after the for loop is done executing.

AAI Services, Textron
dpechacek@aai.textron.com
David.Pechacek@gmail.com

 

Hi David,

Thanks for the response. This was a snippet of example code. It was the curly brackets round the for loop that I was missing. Kicking myself now as have been experimenting with this for hours!!!

Thanks

Mark